// payment_result.js
var api = require('../../utils/api');

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ticketId: "",
    checkId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var ticketId = options.ticketId;
    this.setData({
      "ticketId": ticketId
    });
    this.getCheckStations();
  },
   /**
   * 获取检票站点列表数据
   */
  getCheckStations: function () {
    var ticketId = this.data.ticketId;
    var url = api.getCheckStations();
    url += "?ticketId=" + ticketId;
    var that = this;
    api.request(url, 'GET', '', function (res, err) {
      that.setData({ stations: res });
    });
  },checkTicket(e){
    
    var id = e.currentTarget.dataset.id;
    var stations = this.data.stations;
    for (var i = 0; i < stations.length;i++){
      debugger
      var sId = stations[i].id;
      if (sId == id && !stations[i].isChoose){
        this.data.checkId = sId;
        stations[i].controllerStyle ='-5rpx -225rpx';
        stations[i].isChoose=true;
      }else{
        this.data.checkId='';
        stations[i].controllerStyle = '-61rpx -226rpx';
        stations[i].isChoose = false;
      }
    }

    this.setData({ stations: stations });
  },
  confirmCheck(){
    var openid = app.globalData.opendId;
    var checkId = this.data.checkId;

    if (checkId){
      wx.showToast({
        title: '请选择站点',
        icon: 'succes',
        duration: 1000,
        mask: true
      });
      return;
    }
    var url = api.checkTicket();
    var that=this;
    url += "?id=" + checkId + "&openid=" + openid; 
    api.request(url, 'POST', '', function (res, err) {
      wx.showToast({
        title: '检票成功',
        icon: 'succes',
        duration: 1000,
        mask: true
      });
      that.getCheckStations();
    });
  },
  cancelCheck:function(){
    wx.switchTab({
      url: '/pages/personnel/personnel',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  }
})
